#!/bin/tcsh
#
#  This script runs NWChem on mnemosyne
#
module load mpich
module load nwchem/6.5
#
setenv NWCHEM_PROCS 4
setenv NWCHEM_MEMORY "1200 mb"
setenv NWCHEM_SCRATCH /home/mark/nwchem/scratch
#
set procid=`echo $$`
setenv JOBNAME `ps -p $procid | grep $procid | awk '{print $4}'`
setenv NWCHEM_ROOT `echo $JOBNAME | awk -F_ '{print $1}'`
setenv NWCHEM_SUFFIX `echo $JOBNAME | awk -F_ '{print $2}'`
mkdir $NWCHEM_SCRATCH/$procid
#
# Build the input file
#
cat << finis > $JOBNAME.nw
title "Diamond - geometry and unit cell optimization"

start  $NWCHEM_ROOT
permanent_dir $cwd
scratch_dir $NWCHEM_SCRATCH/$procid
memory $NWCHEM_MEMORY
ecce_print $JOBNAME.ecce

charge 0

#**** Enter the geometry using fractional coordinates ****
geometry center noautosym noautoz print 
  system crystal 
    lat_a 3.56d0 
    lat_b 3.56d0 
    lat_c 3.56d0 
    alpha 90.0d0 
    beta  90.0d0 
    gamma 90.0d0 
  end
  symmetry Fd-3m
  C  0.00000d0  0.00000d0  0.00000d0
end
 
nwpw 
  ewald_rcut 3.0
  ewald_ncut 8  #The default value of 1 needs to be increased for small cells
  lmbfgs
  xc pbe96
  dplot
    vectors $NWCHEM_ROOT.movecs
    density total $NWCHEM_ROOT.cube
  end
end

driver 
  clear 
  maxiter 40
end

set nwpw:cif_filename diamond.opt  # create a CIF file containing optimization history 
set includestress .true.           # this option tells driver to optimize the unit cell
task pspw optimize ignore

task pspw pspw_dplot
finis
#
#   Run the job
#
mpirun -np $NWCHEM_PROCS nwchem $JOBNAME.nw >& $JOBNAME.nwo
#
#   Clean up scratch directory
rm -rf $NWCHEM_SCRATCH/$procid

